#! /usr/bin/python

def main():
    print max([sum([int(k) for k in str(a**b)]) for b in range(100) for a in range(100)])

if __name__ == '__main__':
    main()
